import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

// 连接数据库
public class ConnectDB {
    /**
     * 获取数据库连接
     * @return Connection
     * @throws Exception
     */
    public static Connection getConnection() throws Exception{
        // 注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        // 获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/test1";
        String userName = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url, userName, password);
        return conn;
    }
}
